package com.jc.service.common.model;

/**
 * 用户上下文，用于存储当前登录用户信息
 */
public class UserContext {
    private static final ThreadLocal<LoginUser> userHolder = new ThreadLocal<>();

    public static void setUser(LoginUser user) {
        userHolder.set(user);
    }

    public static LoginUser getUser() {
        return userHolder.get();
    }

    public static String getLoginName() {
        LoginUser user = getUser();
        return user != null ? user.getLoginName() : null;
    }

    public static String getFullName() {
        LoginUser user = getUser();
        return user != null ? user.getFullName() : null;
    }

    public static String getTenantId() {
        LoginUser user = getUser();
        return user != null ? user.getTenantId() : null;
    }

    public static void clear() {
        userHolder.remove();
    }
}